package com.meritdata.cloud.data.service.application.model; /***********************************************************************
 * Module:  TD_DATA_API_APP.java
 * Author:  Lenovo
 * Purpose: Defines the Class TD_DATA_API_APP
 ***********************************************************************/

import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * 数据应用表
 */

@Entity
@Table(name = "TD_DATA_API_APP")
public class Application {
    /**
     * 应用ID:ID
     */

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 应用Key:KEY
     */
    @Column(name = "APP_KEY")
    private String key;
    /**
     * 应用Secret:SECRET
     */
    @Column(name = "SECRET")
    private String secret;
    /**
     * 加密证书:CREDENTIAL
     */
    @Column(name = "CREDENTIAL")
    @Type(type = "org.hibernate.type.MaterializedBlobType")
    private byte[] credential;

    /**
     * 加密证书:CREDENTIAL
     */
    @Column(name = "CREDENTIAL_NAME")
    private String credentialName;

    /**
     * 应用名称:NAME
     */
    @Column(name = "NAME")
    private String name;

    /**
     * 有效日期:EXPIRETIME
     @Column(name = "EXPIRETIME")
     private Date expiretime;
     */

    /**
     * 有效时长
     */
    @Column(name = "DURATION")
    private int duration;

    /**
     * 时长单位
     * 分钟/小时/天 -> 1/2/3
     */
    @Column(name = "DURATION_UNIT")
    private int durationUnit;
    /**
     * 应用描述:DESC
     */
    @Column(name = "DESCRIPTION", length = 1000)
    private String desc;
    /**
     * 创建时间:CREATE_TIME
     */
    @Column(name = "CREATE_TIME")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 修改时间:UPDATE_TIME
     */
    @Column(name = "UPDATE_TIME")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 创建人ID:CREATOR
     */
    @Column(name = "CREATOR")
    private String creator;
    /**
     * 修改人ID:REVISER_ID
     */
    @Column(name = "REVISER_ID")
    private String reviserId;

    /**
     * 应用限流次数
     */
    @Column(name = "APILIMIT")
    private int apiLimit;

    public Application() {
    }

    public Application(Long id, String key, String secret, String credentialName, String name,
                       int duration, int durationUnit, String desc, Date createTime,
                       Date updateTime, String creator, String reviserId, int apiLimit) {
        this.setId(id);
        this.setKey(key);
        this.setSecret(secret);
        this.setCredentialName(credentialName);
        this.setName(name);
        this.setDuration(duration);
        this.setDurationUnit(durationUnit);
        this.setDesc(desc);
        this.setCreateTime(createTime);
        this.setUpdateTime(updateTime);
        this.setCreator(creator);
        this.setReviserId(reviserId);
        this.setApiLimit(apiLimit);
    }

    @Override
    public String toString() {
        return "Application{" +
                "id=" + id +
                ", key='" + key + '\'' +
                ", secret='" + secret + '\'' +
                ", credentialName='" + credentialName + '\'' +
                ", name='" + name + '\'' +
                ", duration=" + duration +
                ", durationUnit=" + durationUnit +
                ", desc='" + desc + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", creator='" + creator + '\'' +
                ", reviserId='" + reviserId + '\'' +
                ", apiLimit=" + apiLimit +
                '}';
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public byte[] getCredential() {
        return credential;
    }

    public void setCredential(byte[] credential) {
        this.credential = credential;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public int getDurationUnit() {
        return durationUnit;
    }

    public void setDurationUnit(int durationUnit) {
        this.durationUnit = durationUnit;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getReviserId() {
        return reviserId;
    }

    public void setReviserId(String reviserId) {
        this.reviserId = reviserId;
    }

    public int getApiLimit() {
        return apiLimit;
    }

    public void setApiLimit(int apiLimit) {
        this.apiLimit = apiLimit;
    }

    public String getCredentialName() {
        return credentialName;
    }

    public void setCredentialName(String credentialName) {
        this.credentialName = credentialName;
    }
}